<template>
  <el-dialog :title="title" :visible.sync="visible" width="600px" append-to-body :destroy-on-close="true">
    <el-form ref="form" :model="form" label-width="100px">
      <el-form-item label="名称" prop="name">
        <el-input v-model="form.name"></el-input>
      </el-form-item>
      <el-form-item type="number" label="最小值" prop="min">
        <el-input v-model="form.min"></el-input>
      </el-form-item>
      <el-form-item label="最大值" prop="min">
        <el-input type="number" v-model="form.max"></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button :loading="buttonLoading" type="primary" @click="submitForm"> 保 存</el-button>
      <el-button @click="cancel">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { saveScoreLevel } from '@/api/project/score-level'
export default {
  name: 'ScoreLevelModal',
  data() {
    return {
      title: '得分区间',
      visible: false,
      form: {},
      buttonLoading: false,
      formKey: ''
    }
  },
  created() {
    this.formKey = this.$route.query.key
  },
  methods: {
    add() {
      this.reset()
      this.visible = true
    },
    reset() {
      this.resetForm('form')
      this.form = {}
    },
    update() {
      this.visible = true
    },
    cancel() {
      this.visible = false
    },
    submitForm() {
      this.form.formKey = this.formKey
      saveScoreLevel(this.form).then((res) => {
        this.$emit('ok')
        this.visible = false
      })
    }
  }
}
</script>

<style scoped></style>
